import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../views/Login";
import Home from "../views/Home";
import ArticleList from "../components/article/ArticleList";
import ArticlePublish from "../components/article/ArticlePublish";
import UserManage from "../components/user/UserManage";
import CategoryManage from "../components/category/CategoryManage";
import DataManage from "../components/data/DataManage";
import ArticleDetails from "../components/article/ArticleDetails";

Vue.use(VueRouter)
const routes = [
    {
        path: '/',
        name: 'Login',
        component: Login,
        hidden:true
    },
    {
        path: '/home',
        name: 'Home',
        component: Home,
        hidden:true
    },
    {
        path: '/home',
        name: 'Home',
        component: Home,
        hidden:false,
        meta:{
            title:'文章管理',
            icon:'el-icon-notebook-1',
            sec:true,
            roles:[
                'ROLE_admin','ROLE_user'
            ]
        },
        children:[
            {
                path: '/articleList',
                name: 'ArticleList',
                component: ArticleList,
                hidden:false,
                meta:{
                    title:'文章列表'
                }
            },
            {
                path: '/articlePublish',
                name: 'ArticlePublish',
                component: ArticlePublish,
                hidden:false,
                meta:{
                    title:'发布文章'
                }
            },
            {
                path: '/articleDetails',
                name: 'ArticleDetails',
                component: ArticleDetails,
                hidden:true,
                meta:{
                    title:'文章详情'
                }
            }
        ]
    },
    {
        path: '/home',
        name: 'Home',
        component: Home,
        hidden:false,
        meta:{
            sec:false
        },
        children:[
            {
                path: '/userManage',
                name: 'UserManage',
                component: UserManage,
                meta:{
                    title:'用户管理',
                    icon:'el-icon-user',
                    roles:[
                        'ROLE_admin'
                    ]
                }
            },
            {
                path: '/categoryManage',
                name: 'CategoryManage',
                component: CategoryManage,
                meta:{
                    title:'栏目管理',
                    icon:'el-icon-s-grid',
                    roles:[
                        'ROLE_admin'
                    ]
                }
            },
            {
                path: '/dataManage',
                name: 'DataManage',
                component: DataManage,
                meta:{
                    title:'数据统计',
                    icon:'el-icon-s-data',
                    roles:[
                        'ROLE_admin','ROLE_user'
                    ]
                }
            }
        ]
    }
]
import {Message} from "element-ui";
import {validateRangeInOneMonth} from "element-ui/src/utils/date-util";

const router = new VueRouter({
    routes
})

router.beforeEach((to, from, next) => {
    if(to.path=='/'){
        window.document.body.style.background='#2d3a4b';
        next();
    }else{
        let user = window.sessionStorage.getItem('loginUser');
        if(user!=null){
            window.document.body.style.background='white';
            next();
        }else{
            Message.warning({message:'请先登录！'});
            next('/');
        }
    }
})

export default router